﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace ControlStock.Repositorio
{
    public class Conexion
    {
        SqlConnection Conn;
        SqlCommand Comando;
        public Conexion()
        {
            string ConnStr = @"Data Source=(local) ;Initial Catalog=STOCKSERVICIO; Integrated Security=SSPI;";

            Conn = new SqlConnection(ConnStr);
            try
            {
                Conn.Open();
            }
            catch (SqlException ex)
            {
                
            }
        }

        public int Insertar(String Consulta)
        {
            if (Conn.State == ConnectionState.Closed)
                Conn.Open();
            Comando = Conn.CreateCommand();
            Comando.CommandText = Consulta;
            return Convert.ToInt32(Comando.ExecuteScalar());
        }

        public void ModificarEliminar(String Consulta)
        {
            if (Conn.State == ConnectionState.Closed)
                Conn.Open();
            Comando = Conn.CreateCommand();
            Comando.CommandText = Consulta;
            Comando.ExecuteNonQuery();
        }

        public DataTable Buscar(String Consulta)
        {
            if (Conn.State == ConnectionState.Closed)
                Conn.Open();
            Comando = Conn.CreateCommand();
            Comando.CommandText = Consulta;
            SqlDataAdapter Adaptador = new SqlDataAdapter(Comando);
            DataTable Tabla = new DataTable();
            Adaptador.Fill(Tabla);
            return Tabla;
        }

    }
}
